package ducna.misscall.screen.misscall.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import ducna.alozo.misscall.R;
import ducna.misscall.common.model.DetailMissCall;

public class ListDetailMissCallAdapter extends BaseAdapter{
	private ArrayList<DetailMissCall> mArrayMissCall;
	
	private Context mContext;

	public ListDetailMissCallAdapter(Context context) {
		this.mContext = context;
		mArrayMissCall = new ArrayList<DetailMissCall>();
	}
	
	/**
	 * @param mArrayMissCall the mArrayMissCall to set
	 */
	public void setArrayMissCall(ArrayList<DetailMissCall> mArrayMissCall) {
		if (mArrayMissCall != null) {
			this.mArrayMissCall = mArrayMissCall;
			notifyDataSetChanged();
		}
	}


	@Override
	public int getCount() {
		return mArrayMissCall.size();
	}

	@Override
	public Object getItem(int position) {
		return mArrayMissCall.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		final ViewHolder holder;
		if (row == null) {
			LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			row = mInflater.inflate(R.layout.item_list_detail_miss_call, null);
			holder = new ViewHolder();
			holder.textViewIndex = (TextView) row.findViewById(R.id.textViewIndex);
			holder.textViewDate = (TextView) row.findViewById(R.id.textViewDate);
			holder.textViewTime = (TextView) row.findViewById(R.id.textViewTime);
			row.setTag(holder);
		} else {
			holder = (ViewHolder) row.getTag();
		}
		
		DetailMissCall detail = mArrayMissCall.get(position);
		holder.textViewDate.setText(detail.getDate());
		holder.textViewTime.setText(detail.getTime());
		holder.textViewIndex.setText((position + 1) + "");
		return row;
	}
	static class ViewHolder {
		TextView textViewDate;
		TextView textViewTime;
		TextView textViewIndex;
		
	}
}
